﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Webcam.Image
{
    /// <summary>
    /// A rectangle
    /// </summary>
    public class Rectangle
    {
        Point topLeft;
        int width = 0;
        int height = 0;

        /// <summary>Top Left point</summary>
        public Point TopLeft { get { return topLeft; } }

        /// <summary>Bottom Right point</summary>
        public Point BottomRight
        {
            get
            {
                return new Point(topLeft.X + width -1, topLeft.Y + height -1);
            }
        }

        /// <summary>Width of the rectangle</summary>
        public int Width { get { return width; } }

        /// <summary>Height of the rectangle</summary>
        public int Height { get { return height; } }

        /// <summary>
        /// Create a rectangle using oposite corners
        /// </summary>
        /// <param name="corner"></param>
        /// <param name="corner2"></param>
        public Rectangle(Point corner, Point corner2)
        {
            // find the min and max values of x and y
            int minX;
            int minY;
            int maxX;
            int maxY;

            if (corner.X < corner2.X)
            {
                minX = corner.X;
                maxX = corner2.X;
            }
            else
            {
                maxX = corner.X;
                minX = corner2.X;
            }

            if (corner.Y < corner2.Y)
            {
                minY = corner.Y;
                maxY = corner2.Y;
            }
            else
            {
                maxY = corner.Y;
                minY = corner2.Y;
            }

            topLeft = new Point(minX, minY);

            width = maxX - minX + 1;
            height = maxY - minY + 1;
        }

        /// <summary>
        /// Create a rectangle with the top left point, height and width
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public Rectangle(int x, int y, int width, int height)
        {
            topLeft = new Point(x, y);
            this.height = height;
            this.width = width;
        }

    }
}
